from logging import INFO
from typing import Dict, Any

from ctaf_core.ctaf_utils.file_process_util import load_json_file


class CTAFsettings:

    DEFAULT_CTAF_SETTINGS: Dict[str, Any] = {
    "load.bundles": "",

    "log.active": True,
    "log.level": INFO,
    "log.console": True,
    "log.file": True,
    "log.rotatingFileMaxBytes": 1024 * 1024 * 10,
    "log.rotatingFileBackupCount": 10,

    "busServiceServerSettingFilename": "bus_service_server_setting.json",
    "busServiceClientSettingFilename": "bus_service_client_setting.json",
    "localServiceServerSettingFilename": "local_service_server_setting.json",
    "gatewaySettingFilename": "gateway_setting.json",
    "quartzTaskSettingFilename": "quartz_task_setting.json",
    "dbSettingFilename": "db_setting.json",
    "quartzSchedulerThreadPoolSize": 20
    }

    @staticmethod
    def load_setting(user_setting_filename: str) -> None:
        """读取配置文件"""
        if not user_setting_filename:
            return
        else:
            user_settings: Dict[str, Any] = load_json_file(user_setting_filename)
            CTAFsettings.DEFAULT_CTAF_SETTINGS.update(user_settings)

    @staticmethod
    def get_setting(setting_name: str) -> Any:
        if not setting_name:
            return
        else:
            return CTAFsettings.DEFAULT_CTAF_SETTINGS.get(setting_name)